//
//  RHInvChartHeaderView.m
//  RuiHeAppApp
//
//  Created by Yan Chen on 2024/6/14.
//

#import "RHInvChartHeaderView.h"
#import "RHEndPointModel.h"
#import "RHBatteryView.h"
#import "RHTopoModel.h"
#import "RHDeviceModel.h"

@interface RHInvChartHeaderView()

@property (nonatomic, strong) QMUILabel *snTitleLab;

@property (nonatomic, strong) QMUILabel *snContentLab;

@property (nonatomic, strong) QMUILabel *versionTitleLab;

@property (nonatomic, strong) QMUILabel *versionContentLab;

@property (nonatomic, strong) QMUILabel *mainLab;

@property (nonatomic, strong) QMUILabel *secondLab;

@property (nonatomic, strong) QMUILabel *dspLab;

@property (nonatomic, strong) QMUILabel *lcdLab;

@property (nonatomic ,strong) UIView *pointView;


@property (nonatomic ,strong) NSArray *titles;
//大类型名称(INV)
@property (nonatomic ,strong) RHEndPointTypeModel *endpointTypeModel;
@property (nonatomic ,strong) RHDeviceModel *deviceModel;

@property (nonatomic ,strong) RHBatteryView *batteryView;
@property (nonatomic, strong) QMUILabel *statusLab;
@property (nonatomic, strong) QMUILabel *socLab;
@property (nonatomic, strong) QMUILabel *timeTitleLab;
@property (nonatomic, strong) QMUILabel *timeLab;
@end
@implementation RHInvChartHeaderView


-(instancetype)initWithEndPointTypeModel:(RHEndPointTypeModel*)endpointTypeModel deviceModel:(RHDeviceModel*)deviceModel;
{
    if(self = [super init]){
        _endpointTypeModel = endpointTypeModel;
        _deviceModel = deviceModel;
        self.titles  = @[@"SN"];
        if ([endpointTypeModel.endpointTypeCode isEqualToString:@"InvVoltronicLv"]) {
            self.titles  = @[@"SN",@"主CPU",@"次CPU",@"DSP"];
        }

        if ([endpointTypeModel.endpointTypeCode isEqualToString:@"InvRenacHv"]||
            [endpointTypeModel.endpointTypeCode isEqualToString:@"InvSolisLv"]) {
            self.titles  = @[@"SN",@"软件版本",@"硬件版本",@"内网协议",@"数据更新时间"];
        }else if( [endpointTypeModel.endpointTypeCode isEqualToString:@"InvMegarevoLv"]) {
            self.titles  = @[@"SN",@"软件版本",@"硬件版本",@"内网协议",@"ARM",@"DSP",@"数据更新时间"];
        }else if([endpointTypeModel.endpointTypeCode isEqualToString:@"EMS"]) {
            self.titles  = @[@"EMS SN",@"软件版本",@"硬件版本",@"内网协议",@"数据更新时间"];
        }else if([endpointTypeModel.endpointTypeCode isEqualToString:@"EMU"]) {
            self.titles  = @[@"EMU SN",@"软件版本",@"硬件版本",@"内网协议",@"数据更新时间"];
        }else if([endpointTypeModel.endpointTypeCode isEqualToString:@"Master"]) {
            self.titles  = @[@"Master SN",@"软件版本",@"硬件版本",@"内网协议",@"数据更新时间"];
        }else if([endpointTypeModel.endpointTypeCode isEqualToString:@"Pack"]) {
            self.titles  = @[@"Pack SN",@"软件版本",@"硬件版本",@"内网协议",@"数据更新时间"];
        }else if([endpointTypeModel.endpointTypeCode hasPrefix:@"Pcs"]) {
            self.titles  = @[@"PCS SN",@"软件版本",@"硬件版本",@"内网协议",@"数据更新时间"];
        }else if([endpointTypeModel.endpointTypeCode isEqualToString:@"MTR"]) {
            self.titles  = @[@"Meter SN",@"软件版本",@"硬件版本",@"内网协议",@"数据更新时间"];
        }else if([endpointTypeModel.endpointTypeCode isEqualToString:@"LCU"]) {
            self.titles  = @[@"LCU SN",@"软件版本",@"硬件版本",@"内网协议",@"数据更新时间"];
        }else if([endpointTypeModel.endpointTypeCode isEqualToString:@"DHM"]) {
            self.titles  = @[@"DHM SN",@"软件版本",@"硬件版本",@"内网协议",@"数据更新时间"];
        }else if([endpointTypeModel.endpointTypeCode isEqualToString:@"Power"]) {
            self.titles  = @[@"Pack SN",@"软件版本",@"硬件版本",@"内网协议",@"数据更新时间"];
        }else if([endpointTypeModel.endpointTypeCode isEqualToString:@"ACU"]) {
            self.titles  = @[@"ACU SN",@"软件版本",@"硬件版本",@"内网协议",@"数据更新时间"];
        }else if ([endpointTypeModel.endpointTypeCode isEqualToString:@"DCDC"]) {
            self.titles  = @[@"DCDC SN",@"软件版本",@"硬件版本",@"内网协议",@"数据更新时间"];
        }else{
            self.titles  = @[@"SN",@"软件版本",@"硬件版本",@"内网协议",@"数据更新时间"];
        }
        
        //61度电没有硬件版本 , 只有 ems 才有硬件版本
        if ([self.deviceModel.deviceTypeCode is61DeviceType]&& ![endpointTypeModel.endpointTypeCode isEqualToString:@"EMS"]) {
            __block NSInteger remove_index = -1;
            NSMutableArray *arrM = [NSMutableArray arrayWithArray:self.titles];
            [self.titles enumerateObjectsUsingBlock:^(NSString*  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                if ([obj isEqualToString:@"硬件版本"]) {
                    remove_index = idx;
                }
            }];
            if (remove_index != -1) {
                [arrM removeObjectAtIndex:remove_index];
            }
            self.titles = arrM.copy;
        }
        
        
        if ([endpointTypeModel.endpointTypeCode isEqualToString:@"Pack"]||
            endpointTypeModel.nodes.count>1) {
            [self setupPackUI];
        }else{
            [self setupUI];
        }
       
    }
    return self;
}
- (void)setEndPointModel:(RHEndPointModel *)endPointModel
{
    _endPointModel = endPointModel;
    
//    if(endPointModel.state == 1){//在线
//        _pointView.backgroundColor = CMainColorGreen;
//        _snContentLab.textColor = CMainColorGreen;
//    }else if (endPointModel.state == 2){//失联
//        _pointView.backgroundColor = kCOLOR_HEX(@"BBBBBB");
//        _snContentLab.textColor = kCOLOR_HEX(@"BBBBBB");
//    }
    
    //大多数都是 5 个, 个别不一样的另作处理
    //SN
    QMUILabel *lab1 = [self viewWithTag:200];
    lab1.text = ValidNullDataToString(endPointModel.sn, @"--");
    
    //软件版本
    QMUILabel *lab2 = [self viewWithTag:201];
    lab2.text = ValidNullDataToString(endPointModel.lastVersion, @"--");
    
    //硬件版本
    QMUILabel *lab3 = [self viewWithTag:202];
    lab3.text = ValidNullDataToString(endPointModel.hardVersion, @"--");
    
    //内网协议
    QMUILabel *lab4 = [self viewWithTag:203];
    lab4.text = ValidNullDataToString(endPointModel.prtclVer, @"--");
    
    //系统时间
    QMUILabel *lab5 = [self viewWithTag:204];
    lab5.text = [NSDate dateStringWithTimeInterval:[endPointModel.time integerValue]/1000 formatter:@"yyyy-MM-dd HH:mm:ss"];
    
    
    //逆变器
    if ([self.endpointTypeModel.endpointTypeCode isEqualToString:@"InvVoltronicLv"]){
        //日月元
       //主CPU
        lab2.text = ValidNullDataToString(endPointModel.mainCpu, @"--");
        //次CPU
        lab3.text = ValidNullDataToString(endPointModel.secondCpu, @"--");
        lab4.text = ValidNullDataToString(endPointModel.dsp, @"--");
        
    }else if ([self.endpointTypeModel.endpointTypeCode isEqualToString:@"InvMegarevoLv"]) { //麦格瑞能
        //arm
        lab4.text = endPointModel.arm;
        //dsp
        lab5.text = endPointModel.dsp;
        
        QMUILabel *lab6 = [self viewWithTag:206];//时间
        lab6.text = [NSDate dateStringWithTimeInterval:[endPointModel.time integerValue]/1000 formatter:@"yyyy-MM-dd HH:mm:ss"];
    }else if ([self.endpointTypeModel.endpointTypeCode isEqualToString:@"InvRenacHv"]) {//纳通
       //显示 5 个,不用再作处理

    }else if([self.deviceModel.deviceTypeCode is61DeviceType] && ![self.endpointTypeModel.endpointTypeCode isEqualToString:@"EMS"]){
        //61度电没有硬件版本
        //内网协议
        lab3.text = ValidNullDataToString(endPointModel.prtclVer, @"--");
       //系统时间
        lab4.text = [NSDate dateStringWithTimeInterval:[endPointModel.time integerValue]/1000 formatter:@"yyyy-MM-dd HH:mm:ss"];

    }
 
}

-(void)setTopoModel:(RHTopoModel *)topoModel
{
    _topoModel = topoModel;
    if ([topoModel.status integerValue] == 0) {//在线
        //0 待机 1 充电 2 放电
        switch (topoModel.workStatus) {
            case 0:
                self.statusLab.text = @"待机".rh_localized;
                break;
            case 1:
                self.statusLab.text = @"充电".rh_localized;
                break;
            case 2:
                self.statusLab.text = @"放电".rh_localized;
                break;
            default:
                self.statusLab.text = @"--";
                break;
        }
    }else{
        self.statusLab.text = @"离线".rh_localized;
    }
    
    
    NSDecimalNumber *socValue = [NSDecimalNumber decimalNumberWithDouble:topoModel.soc];
    self.socLab.text = [NSString stringWithFormat:@"%@%%",socValue];
    self.batteryView.soc = topoModel.soc /100.0f;
    
    NSInteger timeInterval = 0;
    
    if ([topoModel.batPwr floatValue]>0) {
        timeInterval = [topoModel.chgTim integerValue];
        self.timeTitleLab.text = [NSString stringWithFormat:@"%@:",@"备电时长".rh_localized];
    }
    if ([topoModel.batPwr floatValue]<0) {
        timeInterval = [topoModel.dischgTim integerValue];
        self.timeTitleLab.text = [NSString stringWithFormat:@"%@:",@"剩余放电时长".rh_localized];
    }
    NSInteger hour = timeInterval / 60 ;
    NSInteger minute = timeInterval % 60;
    self.timeLab.text = [NSString stringWithFormat:@"%ld %@ %ld %@",hour,@"小时".rh_localized,minute,@"分".rh_localized];
    if(timeInterval == 0){
        self.timeLab.text = @"";
        self.timeTitleLab.text = @"";
    }
    
    if ([topoModel.status integerValue] == 1) {//离线
        self.statusLab.text = @"离线".rh_localized;
        self.timeLab.text = @"";
        self.timeTitleLab.text = @"";
    }
}

- (void)setupUI{
    kWeakSelf;
    self.backgroundColor = CFTabViewBgColor;
    self.frame = CGRectMake(0, 10, SCREEN_WIDTH,140);
    UIView *bgView =  [[UIView alloc] initWithFrame:CGRectMake(15, 10, SCREEN_WIDTH-30,140)];
    [bgView setBackgroundColor:UIColor.whiteColor];
    
    bgView.layer.masksToBounds = YES;
    [bgView rounded:8 width:1 color:kBorderColor];
    [self addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.insets(UIEdgeInsetsMake(10, 15, 0, 15));
    }];

    
    __block UIView *lastView;
    //根据要显示的信息创建label
    
    [self.titles enumerateObjectsUsingBlock:^(NSString*  _Nonnull title, NSUInteger idx, BOOL * _Nonnull stop) {
        UIView *itemView = [self itemViewWithTitle:title index:idx];
        [bgView addSubview:itemView];
        if (lastView) {
            [itemView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.right.mas_offset(0);
                make.top.equalTo(lastView.mas_bottom);
                make.height.equalTo(lastView);
            }];
        }else{
            [itemView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.right.mas_offset(0);
                make.top.mas_offset(5);
                make.height.offset(44);
            }];
        }
        lastView = itemView;
        //线条
        if (idx != weakSelf.titles.count-1) {
            UIView *line = kView;
            line.backgroundColor = kCOLOR_HEX(@"#EBEDF0");
            [itemView addSubview:line];
            [line mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_offset(15);
                make.right.mas_offset(-15);
                make.height.offset(1);
                make.bottom.mas_offset(0);
            }];
        }
    }];
    [lastView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_offset(-5);
    }];
    
    self.frame = CGRectMake(0, 0, kUI_WINDOW_W, 44*self.titles.count+20);
}

-(void)setupPackUI
{
    kWeakSelf;
    self.backgroundColor = CFTabViewBgColor;
    UIView *top_refView;
    if ([self.endpointTypeModel.endpointTypeCode isEqualToString:@"Pack"]) {
        //-------- 电芯数据
        UIView *batCellView = [[UIView alloc] init];
        [batCellView rounded:8 width:1 color:kBorderColor];
        [batCellView setBackgroundColor:UIColor.whiteColor];
        [self addSubview:batCellView];
        top_refView = batCellView;
        [batCellView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_offset(15);
            make.left.mas_offset(15);
            make.right.mas_offset(-15);
            
        }];
        
        _batteryView = [[RHBatteryView alloc] init];
        [batCellView addSubview:_batteryView];
        [_batteryView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.equalTo(@(CGSizeMake(33, 18)));
            make.top.mas_offset(15);
            make.left.mas_offset(15);
            
        }];
        
        QMUILabel *statusTitleLab = [[QMUILabel alloc] init];
        statusTitleLab.text = [NSString stringWithFormat:@"%@:",@"状态".rh_localized];
        [statusTitleLab setTextAlignment:NSTextAlignmentLeft];
        [statusTitleLab setFont:[UIFont systemFontOfSize:14]];
        [statusTitleLab setTextColor:kCOLOR_HEX(@"3F4443")];
        [batCellView addSubview:statusTitleLab];
        [statusTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.batteryView.mas_right).offset(5);
            make.centerY.equalTo(weakSelf.batteryView);
        }];
        
        _statusLab = [[QMUILabel alloc] init];
        _statusLab.text = @"--".rh_localized;
        [_statusLab setTextAlignment:NSTextAlignmentLeft];
        [_statusLab setFont:[UIFont systemFontOfSize:14]];
        [_statusLab setTextColor:kCOLOR_HEX(@"3F4443")];
        [batCellView addSubview:_statusLab];
        [_statusLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(statusTitleLab.mas_right);
            make.centerY.equalTo(statusTitleLab);
        }];
        
        _socLab = [[QMUILabel alloc] init];
        _socLab.text = @"--";
        [_socLab setTextAlignment:NSTextAlignmentRight];
        [_socLab setFont:kSYSTEMFONT(12)];
        [_socLab setTextColor:[UIColor colorWithHexString:@"3F4443" alpha:0.6]];
        [batCellView addSubview:_socLab];
        [_socLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.batteryView);
            make.top.equalTo(weakSelf.batteryView.mas_bottom).offset(8);
            make.bottom.mas_offset(-15);
        }];
        
        _timeTitleLab = [[QMUILabel alloc] init];
        _timeTitleLab.text = [NSString stringWithFormat:@"%@:",@"备电时长".rh_localized];
        [_timeTitleLab setTextAlignment:NSTextAlignmentLeft];
        [_timeTitleLab setFont:kSYSTEMFONT(12)];
        [_timeTitleLab setTextColor:[UIColor colorWithHexString:@"3F4443" alpha:0.6]];
        [batCellView addSubview:_timeTitleLab];
        
        [_timeTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.socLab.mas_right).offset(3);
            make.centerY.equalTo(weakSelf.socLab);
        }];
        
        _timeLab = [[QMUILabel alloc] init];
        _timeLab.text = @"--";
        [_timeLab setTextAlignment:NSTextAlignmentRight];
        [_timeLab setFont:kSYSTEMFONT(12)];
        [_timeLab setTextColor:kCOLOR_HEX(@"79E75A")];
        [batCellView addSubview:_timeLab];
        [_timeLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.timeTitleLab.mas_right).offset(5);
            make.centerY.equalTo(weakSelf.timeTitleLab);
        }];
        
        UIImageView *arrowImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"kwt_home_arrow"]];
        [batCellView addSubview:arrowImg];
        [arrowImg   mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.equalTo(@(CGSizeMake(15, 15)));
            make.centerY.mas_offset(0);
            make.right.mas_offset(-15);
        }];
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]init];
        [batCellView addGestureRecognizer:tap];
        [tap.rac_gestureSignal subscribeNext:^(__kindof UIGestureRecognizer * _Nullable x) {
            if(weakSelf.batteryCellBlock){
                weakSelf.batteryCellBlock();
            }
        }];
    }
    
    
    //-------- 选择类型
    UIView *topView =  [[UIView alloc] initWithFrame:CGRectMake(15, 10, SCREEN_WIDTH-30,105)];
    [topView setBackgroundColor:UIColor.whiteColor];
    [topView rounded:8 width:1 color:kBorderColor];
    
    [self addSubview:topView];
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.right.mas_offset(-15);
        if (top_refView) {
            make.top.equalTo(top_refView.mas_bottom).offset(10);
        }else{
            make.top.mas_offset(10);
        }
        
        make.height.offset(105);
    }];
    QMUILabel *titleLab = [QMUILabel labelWithText:@"选择类型".rh_localized font:kBOLDSYSTEMFONT(16) textColor:kCOLOR_HEX(@"#3F4443")];
    titleLab.textAlignment = NSTextAlignmentLeft;
    [topView addSubview:titleLab];
    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.top.mas_offset(10);
        make.right.mas_offset(-15);
    }];
    
    UIView *selectView = kView;
    selectView.backgroundColor = CFTabViewBgColor;
    selectView.layer.cornerRadius = 5;
    selectView.layer.masksToBounds = YES;
    [topView addSubview:selectView];
    [selectView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.top.equalTo(titleLab.mas_bottom).offset(10);
        make.right.mas_offset(-15);
        make.height.offset(45);
        make.bottom.mas_offset(-15);
    }];
    QMUILabel *snLab = [QMUILabel labelWithText:[self.titles firstObject] font:kSYSTEMFONT(14) textColor:kCOLOR_HEX(@"#3F4443")];
    [selectView addSubview:snLab];
    [snLab sizeToFit];
    [snLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.centerY.mas_offset(0);
        make.width.offset(snLab.width);
    }];
    
    _arrowImg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"arrow"]];
    [selectView addSubview:_arrowImg];
    [_arrowImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(20);
        make.right.mas_offset(-10);
        make.centerY.mas_offset(0);
    }];
    //sn
    QMUILabel *contentLab = [QMUILabel labelWithText:@"--" font:kSYSTEMFONT(14) textColor:kCOLOR_HEX(@"3F4443")];
    contentLab.adjustsFontSizeToFitWidth = YES;
    contentLab.minimumScaleFactor = 0.8;
    contentLab.numberOfLines = 2;
    contentLab.tag = 200;
    [selectView addSubview:contentLab];
    [contentLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(snLab.mas_right).offset(15);
        make.right.equalTo(weakSelf.arrowImg.mas_left);
        make.centerY.mas_offset(0);
    }];
    
    QMUIButton *btn = [[QMUIButton alloc]init];
    [selectView addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsZero);
    }];
    [[btn rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(__kindof UIControl * _Nullable x) {
        if(weakSelf.selectBlock){
            weakSelf.selectBlock();
        }
    }];
    
    //------版本信息
    UIView *bottomView =  [[UIView alloc] initWithFrame:CGRectMake(15, 10, SCREEN_WIDTH-30,140)];
    [bottomView setBackgroundColor:UIColor.whiteColor];
    [bottomView rounded:8 width:1 color:kBorderColor];
    [self addSubview:bottomView];
    [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(topView.mas_bottom).offset(10);
        make.left.mas_offset(15);
        make.right.mas_offset(-15);
        make.bottom.mas_offset(0);
    }];

    
    __block UIView *lastView;
    //根据要显示的信息创建label
    
    [self.titles enumerateObjectsUsingBlock:^(NSString*  _Nonnull title, NSUInteger idx, BOOL * _Nonnull stop) {
        //pack 的sn 放在上面而已,这里跳过
        if (idx==0) {
            return;
        }
        
        UIView *itemView = [self itemViewWithTitle:title index:idx];
        [bottomView addSubview:itemView];
        if (lastView) {
            [itemView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.right.mas_offset(0);
                make.top.equalTo(lastView.mas_bottom);
                make.height.equalTo(lastView);
            }];
        }else{
            [itemView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.right.mas_offset(0);
                make.top.mas_offset(5);
                make.height.offset(44);
            }];
        }
        lastView = itemView;
        //线条
        if (idx != weakSelf.titles.count-1) {
            UIView *line = kView;
            line.backgroundColor = kCOLOR_HEX(@"#EBEDF0");
            [itemView addSubview:line];
            [line mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_offset(15);
                make.right.mas_offset(-15);
                make.height.offset(1);
                make.bottom.mas_offset(0);
            }];
        }
    }];
    [lastView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_offset(-5);
    }];
    
    self.frame = CGRectMake(0, 0, kUI_WINDOW_W, 44*self.titles.count+20 + 105 + (top_refView?60:-20));
   
}

-(UIView*)itemViewWithTitle:(NSString *)title index:(NSInteger)index
{
    kWeakSelf;
    
    
    UIView *itemView = kView;
    QMUILabel *titleLab = [[QMUILabel alloc]init];
    [itemView addSubview:titleLab];
    titleLab.text = [NSString stringWithFormat:@"%@",title.rh_localized];
    titleLab.textColor = [UIColor colorWithHexString:@"3F4443" alpha:0.8];
    titleLab.font = kSYSTEMFONT(14);
    titleLab.tag = 100+index;
    titleLab.textAlignment = NSTextAlignmentLeft;
    [titleLab sizeToFit];
    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.centerY.mas_offset(0);
        make.width.offset(titleLab.width+1);
    }];
    
    QMUILabel *contentLab = [[QMUILabel alloc]init];
    [itemView addSubview:contentLab];
    contentLab.text = @"--";
    contentLab.textColor = [UIColor colorWithHexString:@"3F4443" alpha:0.8];
    contentLab.font = kSYSTEMFONT(14);
    contentLab.tag = 200+index;
    contentLab.textAlignment = NSTextAlignmentRight;
    contentLab.numberOfLines = 2;
    contentLab.adjustsFontSizeToFitWidth = YES;
    contentLab.minimumScaleFactor = 0.8;
    [contentLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(titleLab.mas_right).offset(5);
        make.right.mas_offset(-15);
        make.centerY.mas_offset(0);
    }];
    
    //pack才可选
    //日月元
    if ([self.endpointTypeModel.endpointTypeCode isEqualToString:@"InvVoltronicLv"]) {
        if (index == 0 ) {
            self.snTitleLab   = titleLab;
            self.snContentLab = contentLab;
        }
        
        if (index == 1) {
            self.mainLab = contentLab;
        }
        if (index == 2) {
            self.secondLab = contentLab;
        }
        if (index == 3) {
            self.dspLab = contentLab;
        }
    }
    
    
    
    //麦格瑞能
    if ([self.endpointTypeModel.endpointTypeCode isEqualToString:@"InvMegarevoLv"]) {
        if (index == 0 ) {
            self.snTitleLab   = titleLab;
            self.snContentLab = contentLab;
        }
        
        if (index == 4) {
            self.mainLab = contentLab;
        }
        if (index == 5) {
            self.dspLab = contentLab;
        }
        if (index == 6) {
            self.lcdLab = contentLab;
        }
        if (index == 7) {
            self.secondLab = contentLab;
        }
    }
    return itemView;
}


@end
